﻿//********************************************************************************//
//创建日期：<创建日期，2016-05-12>
//创建作者：<孙雪婷，sunxueting@shanghai3h.com>
//功能说明：用户信息查询
//********************************************************************************//

using System;
using System.Data;
using BLL;
using BLL.Access;
using DevExpress.Web;
using Entity;
using Web.Class;

namespace Web.Pages.YongShui._12.ChaXunGL
{
    public partial class YongHuXXCX : BasePage
    {
        protected void btnExport_Click(object sender, EventArgs e)
        {
            ASPxGridViewExporter1.GridViewID = "gvYongHuXXTab1";
            gvYongHuXXTab1.DataSource = dtYongHuXXTab1;
            gvYongHuXXTab1.DataBind();
            var sName = "用户信息";
            gvYongHuXXTab1.Settings.ShowFooter = false;
            ASPxGridViewExporter1.WriteXlsToResponse(sName);
        }

        #region 属性

        /// <summary>
        ///     保存结果集1
        /// </summary>
        private DataTable dtYongHuXXTab1
        {
            get { return ViewState["dtYongHuXXTab1"] as DataTable; }
            set { ViewState["dtYongHuXXTab1"] = value; }
        }

        /// <summary>
        ///     保存结果集2
        /// </summary>
        private DataTable dtYongHuXXTab2
        {
            get { return ViewState["dtYongHuXXTab2"] as DataTable; }
            set { ViewState["dtYongHuXXTab2"] = value; }
        }

        /// <summary>
        ///     保存结果集3
        /// </summary>
        private DataTable dtYongHuXXTab2_N
        {
            get { return ViewState["dtYongHuXXTab2_N"] as DataTable; }
            set { ViewState["dtYongHuXXTab2_N"] = value; }
        }

        /// <summary>
        ///     当前操作项ID
        /// </summary>
        private int yonghuXXTab1_ID
        {
            get { return Convert.ToInt32(ViewState["yonghuXXTab1_ID"]); }
            set { ViewState["yonghuXXTab1_ID"] = value; }
        }

        /// <summary>
        ///     当前操作项ID
        /// </summary>
        private int yonghuXXTab2_ID
        {
            get { return Convert.ToInt32(ViewState["yonghuXXTab2_ID"]); }
            set { ViewState["yonghuXXTab2_ID"] = value; }
        }

        #endregion

        #region 变量

        /// <summary>
        ///     用户信息
        /// </summary>
        private YS_YG_YONGHUXX _YS_YG_YONGHUXX = new YS_YG_YONGHUXX();

        /// <summary>
        ///     用户信息bll
        /// </summary>
        private readonly YS_YG_YONGHUXXBLL _YS_YG_YONGHUXXBLL = new YS_YG_YONGHUXXBLL();

        /// <summary>
        ///     管理部门
        /// </summary>
        private YS_JX_ZHANDIAN _YS_JX_ZHANDIAN = new YS_JX_ZHANDIAN();

        /// <summary>
        ///     管理部门bll
        /// </summary>
        private readonly YS_JX_ZHANDIANBLL _YS_JX_ZHANDIANBLL = new YS_JX_ZHANDIANBLL();

        /// <summary>
        ///     管理块
        /// </summary>
        private YS_JX_GUANLIK _YS_JX_GUANLIK = new YS_JX_GUANLIK();

        /// <summary>
        ///     管理块BLL
        /// </summary>
        private readonly YS_JX_GUANLIKBLL _YS_JX_GUANLIKBLL = new YS_JX_GUANLIKBLL();


        /// <summary>
        ///     局信息BLL
        /// </summary>
        private readonly YS_JX_JUXINXBLL _YS_JX_JUXINXBLL = new YS_JX_JUXINXBLL();

        /// <summary>
        ///     公司信息BLL
        /// </summary>
        private readonly YS_JX_GONGSIXXBLL _YS_JX_GONGSIXXBLL = new YS_JX_GONGSIXXBLL();

        /// <summary>
        ///     存储过程调用类
        /// </summary>
        private readonly SpHelper _SpHelper = new SpHelper();

        /// <summary>
        ///     来函用户调整
        /// </summary>
        private readonly YS_LH_YONGHUTZBLL _YS_LH_YONGHUTZBLL = new YS_LH_YONGHUTZBLL();

        #endregion

        #region 事件

        /// <summary>
        ///     页面加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            //第一次页面加载
            if (!IsPostBack)
                InitData();

            var index = ASPxPageControl1.ActiveTabIndex;

            gvYongHuXXTab1.DataSource = dtYongHuXXTab1;
            gvYongHuXXTab1.DataBind();

            gvFenHuXX.DataSource = dtYongHuXXTab2;
            gvFenHuXX.DataBind();
        }


        /// <summary>
        ///     查询信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnChaXun_Click(object sender, EventArgs e)
        {
            var index = ASPxPageControl1.ActiveTabIndex;
            if (index == 0)
            {
                if (txtShuiLiangYM.Text != "")
                {
                    LoadGridDataTab1();
                    if (dtYongHuXXTab1 == null || dtYongHuXXTab1.Rows.Count < 1)
                    {
                        txtYongHuH2.Text = "";
                        txtYongHuM2.Text = "";
                        txtYongShuiXZ.Text = "";
                        txtHangYeLX.Text = "";
                        txtJuHao.Text = "";
                        txtJuMing.Text = "";
                        txtYongShuiJ2.Text = "";
                        txtSheShuiDXFL.Text = "";
                        txtGongSiH.Text = "";
                        txtGongSiM.Text = "";
                        txtShouFeiFS.Text = "";
                        txtYeWuY.Text = "";
                        txtXingZhengQH.Text = "";
                        txtXingZhengQM.Text = "";
                        txtZiLaiSBS.Text = "";
                        txtHuiGuanBS.Text = "";
                        txtShiKaoHY2.Text = "";
                        txtKaoHeFYBZ.Text = "";
                        txtKaoHeFYBZ2.Text = "";
                        txtYongHuDZ2.Text = "";
                        txtLianXiBM.Text = "";
                        txtLianXiR.Text = "";
                        txtLianXiDH.Text = "";
                        txtYouBian.Text = "";
                        txtKaiHuHM2.Text = "";
                        txtKaiHuYH.Text = "";
                        txtYinHangZH2.Text = "";
                        zjltab1.Text = "共0条";
                    }
                }
            }
            else if (index == 1)
            {
                LoadGridDataTab2();
                if (dtYongHuXXTab2 == null || dtYongHuXXTab2.Rows.Count < 1)
                {
                    zjltab2.Text = "共0条";
                    gvFenHuJG.DataSource = null;
                    gvFenHuJG.DataBind();
                }
            }
        }


        /// <summary>
        ///     管理部门下拉改变事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void cmbGuanLiBM_SelectedIndexChanged(object sender, EventArgs e)
        {
            cmbGuanLiK.Items.Clear();
            cmbGuanLiK.Items.Add("全部", "");
            cmbGuanLiK.SelectedIndex = 0;
            var glbm_now = cmbGuanLiBM.Value != null ? cmbGuanLiBM.Value.ToString() : "全部";
            InitDataAgain(glbm_now);
        }

        /// <summary>
        ///     表格点击行事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <summary>
        ///     tab2下拉框改变事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void cmbHuJiGDLX_SelectedIndexChanged(object sender, EventArgs e)
        {
            LoadGridDataTab2();
        }

        #endregion

        #region 方法

        /// <summary>
        ///     初始化数据
        /// </summary>
        private void InitData()
        {
            gvYongHuXXTab1.SettingsPager.Mode = GridViewPagerMode.EndlessPaging;
            gvFenHuXX.SettingsPager.Mode = GridViewPagerMode.EndlessPaging;
            //水量年月
            var water_y_m = BusinessTool.YS_GETSETTINGSVALUE(eSETTINGS_KEYNAME.WATER_Y_M.ToString());
            //管理部门
            var dtGuanLiBM = _YS_JX_ZHANDIANBLL.SelectYS_JX_ZHANDIANsAll();
            for (var i = 0; i < dtGuanLiBM.Rows.Count; i++)
                if (dtGuanLiBM.Rows[i]["S_ZHANDIANMC"].ToString() != "中心")
                    cmbGuanLiBM.Items.Add(dtGuanLiBM.Rows[i]["S_ZHANDIANMC"].ToString(),
                        dtGuanLiBM.Rows[i]["S_ZHANDIANBH"].ToString());

            //业务员
            LoadYWY();
            txtShuiLiangYM.Text = water_y_m;

            //用水性质和涉水对象
            LoadYSXZ_SSDX();

            //加载局信息和公司信息
            LoadJXX_GSXX();

            var userid = LoginInfo.CurrentUser.UserID;
            var username = LoginInfo.CurrentUser.UserName;
            //根据操作人加载管理部门(站点)
            var dtZhanDian = BusinessTool.GetTextAndValue("View_AS_UserInfo", "ZHANDIANBH", "ROLEID", null,
                string.Format("USERID={0}", userid)).Tables[0];
            var zhandian = dtZhanDian.Rows[0]["TEXT"].ToString(); //站点
            var roleid = dtZhanDian.Rows[0]["VALUE"].ToString(); //9001 业务员，3001 办事处主任
            if (roleid == "9001")
            {
                if (zhandian == "00")
                {
                    cmbYeWuY.Enabled = false;
                    cmbYeWuY.Text = username;
                }
                else
                {
                    cmbGuanLiBM.Enabled = false;
                    cmbYeWuY.Enabled = false;
                    cmbGuanLiBM.Value = zhandian;
                    cmbYeWuY.Text = username;
                    //管理块
                    var dtGuanLiK =
                        _YS_JX_GUANLIKBLL.SelectYS_JX_GUANLIKsDynamic(string.Format("S_ZHANDIAN={0}", zhandian), null);
                    for (var i = 0; i < dtGuanLiK.Rows.Count; i++)
                        cmbGuanLiK.Items.Add(dtGuanLiK.Rows[i]["S_GUANLIKMC"].ToString(),
                            dtGuanLiK.Rows[i]["S_GUANLIKH"].ToString());
                }
            }
            else if (roleid == "3001" || roleid == "4001")
            {
                cmbGuanLiBM.Enabled = false;
                cmbGuanLiBM.Value = zhandian;
                //管理块
                var dtGuanLiK =
                    _YS_JX_GUANLIKBLL.SelectYS_JX_GUANLIKsDynamic(string.Format("S_ZHANDIAN={0}", zhandian), null);
                for (var i = 0; i < dtGuanLiK.Rows.Count; i++)
                    cmbGuanLiK.Items.Add(dtGuanLiK.Rows[i]["S_GUANLIKMC"].ToString(),
                        dtGuanLiK.Rows[i]["S_GUANLIKH"].ToString());
                LoadYWY();
            }
        }

        /// <summary>
        ///     根据站点加载业务员
        /// </summary>
        private void LoadYWY()
        {
            var dtYWY = BusinessTool.GetTextAndValue(
                "View_AS_UserInfo", "USERNAME", "USERID", null,
                cmbGuanLiBM.SelectedIndex == 0
                    ? "ROLENAME like '%业务员%' and department!=313"
                    : string.Format("ZHANDIANBH='{0}' and ROLENAME like '%业务员%' and department!=313", cmbGuanLiBM.Value)
            ).Tables[0];
            var drTemp = dtYWY.NewRow();
            drTemp[0] = "";
            drTemp[1] = 0;
            dtYWY.Rows.InsertAt(drTemp, 0);
            PageTools.BindComboBox(
                cmbYeWuY, dtYWY
            );
            if (cmbYeWuY.Items.Count != 0)
                cmbYeWuY.SelectedIndex = 0;
        }

        /// <summary>
        ///     加载用水性质、涉水对象
        /// </summary>
        private void LoadYSXZ_SSDX()
        {
            //用水性质
            var dt_ysxz = _SpHelper.P_YSCX_YSXZ_SSDX(1).Tables[0];
            for (var i = 0; i < dt_ysxz.Rows.Count; i++)
                cmbYongShuiXZ.Items.Add(dt_ysxz.Rows[i]["XH"] + "_" + dt_ysxz.Rows[i]["NA"], dt_ysxz.Rows[i]["XH"]);
            //涉水对象
            var dt_ssdx = _SpHelper.P_YSCX_YSXZ_SSDX(2).Tables[0];
            for (var i = 0; i < dt_ssdx.Rows.Count; i++)
            {
                cmbSheShuiDXFL_h1.Items.Add(dt_ssdx.Rows[i]["XH"] + "_" + dt_ssdx.Rows[i]["NA"], dt_ssdx.Rows[i]["XH"]);
            }
            //行业分类
            var dt_hhfl = _SpHelper.P_YSCX_YSXZ_SSDX(3).Tables[0];
            for (var i = 0; i < dt_hhfl.Rows.Count; i++)
            {
                cmbSheShuiDXFL_h2.Items.Add(dt_hhfl.Rows[i]["XH"] + "_" + dt_hhfl.Rows[i]["NA"], dt_hhfl.Rows[i]["XH"]);
            }
        }

        /// <summary>
        ///     加载局信息和公司信息
        /// </summary>
        private void LoadJXX_GSXX()
        {
            var dt_jxx = _YS_JX_JUXINXBLL.SelectYS_JX_JUXINXesDynamic("i_leixing=0 and i_jlzt=0", null);
            for (var i = 0; i < dt_jxx.Rows.Count; i++)
                cbmJuXX.Items.Add(dt_jxx.Rows[i]["S_BIANHAO"] + "_" + dt_jxx.Rows[i]["S_MINGCHENG"],
                    dt_jxx.Rows[i]["S_BIANHAO"]);

            var dt_gsxx = _YS_JX_GONGSIXXBLL.SelectYS_JX_GONGSIXXesDynamic("i_leixing=0 and i_jlzt=0", null);
            for (var i = 0; i < dt_gsxx.Rows.Count; i++)
                cmbGongSiXX.Items.Add(dt_gsxx.Rows[i]["S_BIANHAO"] + "_" + dt_gsxx.Rows[i]["S_MINGCHENG"],
                    dt_gsxx.Rows[i]["S_BIANHAO"]);
        }

        /// <summary>
        ///     再次根据管理部门初始化查询条件
        /// </summary>
        /// <param name="glbm">管理部门</param>
        private void InitDataAgain(string glbm)
        {
            if (glbm != "全部")
            {
                //管理块
                var dtGuanLiK =
                    _YS_JX_GUANLIKBLL.SelectYS_JX_GUANLIKsDynamic(string.Format("S_ZHANDIAN={0}", glbm), null);
                for (var i = 0; i < dtGuanLiK.Rows.Count; i++)
                    cmbGuanLiK.Items.Add(dtGuanLiK.Rows[i]["S_GUANLIKMC"].ToString(),
                        dtGuanLiK.Rows[i]["S_GUANLIKH"].ToString());
                //业务员
                LoadYWY();
            }
            else
            {
                cmbYeWuY.Items.Clear();
                //业务员
                LoadYWY();
            }
        }


        /// <summary>
        ///     加载查询数据
        /// </summary>
        private void LoadGridDataTab1()
        {
            string v_zhandian = null, v_guanlikuai = null, v_yonghuh = null, v_yonghum = null, v_yonghudz = null;
            var v_ym = Convert.ToInt32(txtShuiLiangYM.Text);
            string v_yinhangqr = null;
            var v_shoufeifs = 2; //收费方式 0 非托收，1托收
            string v_yongshuixz = null;
            string v_sheshuidx = null;
            string v_shikaohy = null;
            string v_yongshuij = null;
            string v_juxx = null;
            string v_gongsixx = null;
            string v_kaihuhm = null;
            string v_yinhangzh = null;
            var v_ywy = cmbYeWuY.SelectedIndex <= 0 ? null : cmbYeWuY.Value.ToString();
            //站点
            if (cmbGuanLiBM.Value != null)
                v_zhandian = cmbGuanLiBM.Value.ToString();
            //管理块
            if (cmbGuanLiK.Value != null)
                v_guanlikuai = cmbGuanLiK.Value.ToString();

            //用户号、用户名、用户地址
            if (rbnYongHuH.Checked && txtYongHuH.Text != "")
            {
                v_yonghuh = txtYongHuH.Text;
            }
            else if (rbnYongHuM.Checked && txtYongHuM.Text != "")
            {
                v_yonghum = txtYongHuM.Text;
            }
            else if (rbnYongHuDZ.Checked && txtYongHuDZ.Text != "")
            {
                v_yonghudz = txtYongHuDZ.Text;
            }
            else if (rbnShouFeiFS.Checked && cmbShouFeiFS.Text != "") //收费方式
            {
                v_shoufeifs = Convert.ToInt32(cmbShouFeiFS.Value);
            }
            else if (rbnYongShuiXZ.Checked && cmbYongShuiXZ.Text != "") //用水性质
            {
                v_yongshuixz = cmbYongShuiXZ.Value.ToString();
            }
            else if (rbnSheShuiDXFL.Checked) //涉水对象分类
            {
                if (cmbSheShuiDXFL_q1.Text != "" && cmbSheShuiDXFL_h1.Text != "")
                {
                    v_sheshuidx = cmbSheShuiDXFL_q1.Text + cmbSheShuiDXFL_h1.Value;
                    if (cmbSheShuiDXFL_q2.Text != "" && cmbSheShuiDXFL_h2.Text != "")
                    {
                        v_sheshuidx += " AND  S_SHESHUIDXDM ";
                        v_sheshuidx += cmbSheShuiDXFL_q2.Text + cmbSheShuiDXFL_h2.Value;
                    }
                }
            }
            else if (rbnShiKaoHY.Checked && cbmShiKaoHY.Text != "" && txtShiKaoHY.Text != "") //试考核月
            {
                v_shikaohy = cbmShiKaoHY.Text + txtShiKaoHY.Text;
            }
            else if (rbnYongShuiJ.Checked && cbmYongShuiJ.Text != "" && txtYongShuiJ.Text != "") //用水价
            {
                v_yongshuij = cbmYongShuiJ.Text + txtYongShuiJ.Text;
            }
            else if (rbnJuXX.Checked && cbmJuXX.Text != "") //局信息
            {
                v_juxx = cbmJuXX.Value.ToString();
            }
            else if (rbnGongSiXX.Checked && cmbGongSiXX.Text != "") //公司信息
            {
                v_gongsixx = cmbGongSiXX.Value.ToString();
            }
            else if (rbnKaiHuHM.Checked && txtKaiHuHM.Text != "") //开户户名
            {
                v_kaihuhm = txtKaiHuHM.Text;
            }
            else if (rbnYinHangZH.Checked && txtYinHangZH.Text != "") //银行帐号
            {
                v_yinhangzh = txtYinHangZH.Text;
            }
            else if (chkShiFouQR.Checked && cmbShiFouQR.Text != "") //银行是否确认 20190404
            {
                v_yinhangqr = cmbShiFouQR.Value.ToString();
            }
            //this.dtYongHuXXTab1
            dtYongHuXXTab1 = _SpHelper.P_YSCX_YHXXCX(v_zhandian, v_guanlikuai, v_ywy, v_ym, v_yonghuh, v_yonghum,
                v_yonghudz,
                v_shoufeifs, v_yongshuixz, v_sheshuidx, v_shikaohy, v_yongshuij, v_juxx, v_gongsixx, v_kaihuhm,
                v_yinhangzh, 0, v_yinhangqr).Tables[0];
            gvYongHuXXTab1.DataSource = dtYongHuXXTab1;
            gvYongHuXXTab1.DataBind();
            //this.dtYongHuXXTab1 = dt;
            if (dtYongHuXXTab1 != null && dtYongHuXXTab1.Rows.Count > 0)
            {
                zjltab1.Text = "共" + dtYongHuXXTab1.Rows.Count + "条";
                gvYongHuXXTab1.FocusedRowIndex = -1;
                gvYongHuXXTab1.FocusedRowIndex = 0;
                //SetData();
            }
        }

        /// <summary>
        ///     给显示框赋值
        /// </summary>
        private void SetData()
        {
            var dt_temp = _SpHelper.P_YSCX_YHXXCX("", "", "", Convert.ToInt32(txtShuiLiangYM.Text), "", "", "", 2, "",
                "", "", "", "", "", "", "", Convert.ToInt32(gvYongHuXXTab1.GetRowValues(0, "ID")), "").Tables[0];
            if (dt_temp != null && dt_temp.Rows.Count > 0)
            {
                txtYongHuH2.Text = dt_temp.Rows[0]["用户号"].ToString();
                txtYongHuM2.Text = dt_temp.Rows[0]["用户名"].ToString();
                txtYongShuiXZ.Text = dt_temp.Rows[0]["用水性质"].ToString();
                txtHangYeLX.Text = dt_temp.Rows[0]["S_HANGYELEIXMC"].ToString();
                txtJuHao.Text = dt_temp.Rows[0]["局号"].ToString();
                txtJuMing.Text = dt_temp.Rows[0]["局名"].ToString();
                txtYongShuiJ2.Text = dt_temp.Rows[0]["用水价"].ToString();
                txtSheShuiDXFL.Text = dt_temp.Rows[0]["S_SHESHUIDXFLMC"].ToString();
                txtGongSiH.Text = dt_temp.Rows[0]["公司号"].ToString();
                txtGongSiM.Text = dt_temp.Rows[0]["公司名"].ToString();
                txtShouFeiFS.Text = dt_temp.Rows[0]["收费方式"].ToString();
                txtYeWuY.Text = dt_temp.Rows[0]["业务员"].ToString();
                txtXingZhengQH.Text = dt_temp.Rows[0]["行政区号"].ToString();
                txtXingZhengQM.Text = dt_temp.Rows[0]["行政区"].ToString();
                txtZiLaiSBS.Text = dt_temp.Rows[0]["I_ZLSBS"].ToString();
                txtHuiGuanBS.Text = dt_temp.Rows[0]["I_HGBS"].ToString();
                txtShiKaoHY2.Text = dt_temp.Rows[0]["试考核月"].ToString();
                //txtKaoHeFYBZ.Text = "不考核";//20190408 add
                txtKaoHeFYBZ.Text = dt_temp.Rows[0]["考核复用"].ToString() == "0" ? "不考核" : dt_temp.Rows[0]["考核复用"].ToString() == "1" ? "工业" : "非工业";
                txtKaoHeFYBZ2.Text = dt_temp.Rows[0]["考核复用"].ToString(); 
                txtYongHuDZ2.Text = dt_temp.Rows[0]["用户地址"].ToString();
                txtLianXiBM.Text = dt_temp.Rows[0]["联系部门"].ToString();
                txtLianXiR.Text = dt_temp.Rows[0]["联系人"].ToString();
                txtLianXiDH.Text = dt_temp.Rows[0]["联系电话"].ToString();
                txtYouBian.Text = dt_temp.Rows[0]["邮编"].ToString();
                txtKaiHuHM2.Text = dt_temp.Rows[0]["开户户名"].ToString();
                txtKaiHuYH.Text = dt_temp.Rows[0]["开户银行"].ToString();
                txtYinHangZH2.Text = dt_temp.Rows[0]["银行账号"].ToString();
            }
        }

        /// <summary>
        ///     加载tab2页签数据
        /// </summary>
        private void LoadGridDataTab2()
        {
            var val = Convert.ToInt32(cmbHuJiGDLX.Value);
            if (val == 1)
            {
                legend1.InnerText = "分户前用户信息";
                legend2.InnerText = "分户结果";
            }
            else if (val == 2)
            {
                legend1.InnerText = "并户结果";
                legend2.InnerText = "并户前用户信息";
            }
            else if (val == 4)
            {
                legend1.InnerText = "改户前信息";
                legend2.InnerText = "改户结果";
            }
            else if (val == 5)
            {
                legend1.InnerText = "销户前信息";
                legend2.InnerText = "销户结果";
            }

            if (val == 2)
            {
                //并户结果
                dtYongHuXXTab2 = _SpHelper.P_YSCX_YHXXCX_BH().Tables[0];
                gvFenHuXX.DataSource = dtYongHuXXTab2;
                gvFenHuXX.DataBind();
                //                select * from ys_lh_yonghutz   where  i_yuanyongh=1 and i_laihanlx=9
                //and (s_laihanbh is null or exists(select 1 from ys_lh_laihanxx a where a.i_laihanlx=9 and a.s_laihanbh=s_laihanbh 
                //and a.i_liuchengzt=1)) order by s_yonghuh;
                //                select * from customer 
                //where i_state=-1 and i_Action=2
                //and c_userid in (0100503,0101115)
                //and i_jlzt=0;
            }
            else
            {
                dtYongHuXXTab2 = _YS_YG_YONGHUXXBLL.SelectYS_YG_YONGHUXXesDynamic(
                    string.Format(" i_jlzt=-1 and i_leixing=0 and I_YONGHUZT={0} order by s_yonghuh", val), null);
                gvFenHuXX.DataSource = dtYongHuXXTab2;
                gvFenHuXX.DataBind();
            }
            if (dtYongHuXXTab2 != null && dtYongHuXXTab2.Rows.Count > 0)
            {
                zjltab2.Text = "共" + dtYongHuXXTab2.Rows.Count + "条";
                gvFenHuXX.FocusedRowIndex = -1;
                gvFenHuXX.FocusedRowIndex = 0;
                //LoadGridDataTab2_N(val);
            }
        }

        /// <summary>
        ///     根据上面信息显示下列结果
        /// </summary>
        private void LoadGridDataTab2_N(int val)
        {
            var dt_temp =
                _YS_YG_YONGHUXXBLL.SelectYS_YG_YONGHUXXesDynamic(string.Format(" ID='{0}'", yonghuXXTab2_ID), null);
            if (dt_temp != null && dt_temp.Rows.Count > 0)
            {
                var sYuanYHH = dt_temp.Rows[0]["S_YONGHUH"].ToString();
                if (sYuanYHH != "")
                {
                    dtYongHuXXTab2_N = _YS_YG_YONGHUXXBLL.SelectYS_YG_YONGHUXXesDynamic(
                        string.Format("i_leixing=0 and s_yuanyonghuh in ({0}) order by s_yonghuh", sYuanYHH), null);
                    gvFenHuJG.DataSource = dtYongHuXXTab2_N;
                    gvFenHuJG.DataBind();
                }
            }
        }

        /// <summary>
        ///     前台表格行改变事件回调方法
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void ASPxCallback1_Callback(object source, CallbackEventArgs e)
        {
            var id = Convert.ToInt32(hdCollection.Get("ID"));
            if (e.Parameter == "setinfo")
            {
                var msg = "";
                var dt_temp = _SpHelper.P_YSCX_YHXXCX("", "", "", Convert.ToInt32(txtShuiLiangYM.Text), "", "", "", 2,
                    "", "", "", "", "", "", "", "", id, "").Tables[0];
                if (dt_temp != null && dt_temp.Rows.Count > 0)
                    msg = string.Join("|", Convert.ToString(dt_temp.Rows[0]["用户号"]),
                        Convert.ToString(dt_temp.Rows[0]["用户名"]), Convert.ToString(dt_temp.Rows[0]["用水性质"]),
                        Convert.ToString(dt_temp.Rows[0]["局号"]), Convert.ToString(dt_temp.Rows[0]["局名"]),
                        Convert.ToString(dt_temp.Rows[0]["用水价"]), Convert.ToString(dt_temp.Rows[0]["S_SHESHUIDXFLMC"]),
                        Convert.ToString(dt_temp.Rows[0]["公司号"]), Convert.ToString(dt_temp.Rows[0]["公司名"]),
                        Convert.ToString(dt_temp.Rows[0]["收费方式"]), Convert.ToString(dt_temp.Rows[0]["业务员"]),
                        Convert.ToString(dt_temp.Rows[0]["行政区号"]), Convert.ToString(dt_temp.Rows[0]["行政区"]),
                        Convert.ToString(dt_temp.Rows[0]["考核复用"]), Convert.ToString(dt_temp.Rows[0]["试考核月"]),
                        Convert.ToString(dt_temp.Rows[0]["用户地址"]), Convert.ToString(dt_temp.Rows[0]["联系部门"]),
                        Convert.ToString(dt_temp.Rows[0]["联系人"]), Convert.ToString(dt_temp.Rows[0]["联系电话"]),
                        Convert.ToString(dt_temp.Rows[0]["邮编"]), Convert.ToString(dt_temp.Rows[0]["开户户名"]),
                        Convert.ToString(dt_temp.Rows[0]["开户银行"]), Convert.ToString(dt_temp.Rows[0]["银行账号"]),
                        dt_temp.Rows[0]["I_ZLSBS"].ToString(), dt_temp.Rows[0]["I_HGBS"].ToString(),
                        dt_temp.Rows[0]["S_HANGYELEIXMC"].ToString());
                e.Result = e.Parameter + "|0|" + msg;
            }
            else if (e.Parameter == "hjgdxx")
            {
                var val = Convert.ToInt32(cmbHuJiGDLX.Value);
                var dt_temp = new DataTable();
                var msg = "";
                var sYuanYHH = "";
                if (val == 2)
                {
                    dt_temp = _YS_LH_YONGHUTZBLL.SelectYS_LH_YONGHUTZsDynamic(string.Format(" ID='{0}'", id), null);
                    sYuanYHH = dt_temp != null && dt_temp.Rows.Count > 0
                        ? dt_temp.Rows[0]["S_YUANYONGHUH"].ToString()
                        : "";
                }
                else
                {
                    dt_temp = _YS_YG_YONGHUXXBLL.SelectYS_YG_YONGHUXXesDynamic(string.Format(" ID='{0}'", id), null);
                    sYuanYHH = dt_temp != null && dt_temp.Rows.Count > 0 ? dt_temp.Rows[0]["S_YONGHUH"].ToString() : "";
                }
                msg = string.Join("|", Convert.ToString(sYuanYHH));
                e.Result = e.Parameter + "|0|" + msg;
            }
        }

        /// <summary>
        ///     分户结果刷新
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvFenHuJG_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)
        {
            var yhh = hdCollection.Get("yyhh").ToString();
            var val = Convert.ToInt32(cmbHuJiGDLX.Value);
            if (val == 2)
            {
                var arryhh = yhh.Split(',');
                var yhh2 = "'" + string.Join("','", arryhh) + "'";
                dtYongHuXXTab2_N = _YS_YG_YONGHUXXBLL.SelectYS_YG_YONGHUXXesDynamic(
                    string.Format("I_LEIXING=0 AND S_YONGHUH in ({0}) order by s_yonghuh", yhh2), null);
            }
            else
            {
                dtYongHuXXTab2_N = _YS_YG_YONGHUXXBLL.SelectYS_YG_YONGHUXXesDynamic(
                    string.Format("I_LEIXING=0 AND S_YUANYONGHUH = '{0}' order by s_yonghuh", yhh), null);
            }


            gvFenHuJG.DataSource = dtYongHuXXTab2_N;
            gvFenHuJG.DataBind();
        }

        #endregion
    }
}